package me.work.pay.jsyl.app.service;

import android.content.Context;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.service.SerializationService;
import com.google.gson.Gson;

import java.lang.reflect.Type;

import me.work.pay.jsyl.app.RouterHub;

/**
 * @author xubo
 * @date 2018/9/18 10:01
 */
@Route(path = RouterHub.JSON)
public class JsonServiceImpl implements SerializationService {

    @Override
    public void init(Context context) {
    }

    @Override
    public <T> T json2Object(String text, Class<T> clazz) {
        return new Gson().fromJson(text, clazz);
    }

    @Override
    public String object2Json(Object instance) {
        return new Gson().toJson(instance);
    }

    @Override
    public <T> T parseObject(String input, Type clazz) {
        return new Gson().fromJson(input, clazz);
    }

}
